package util;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * ServerResponseThread.java  Date Created: Aug 26, 2013
 *
 * Purpose: To time out after a set number of seconds if client has not heard back from the server.
 *
 * Description: Depending on the 'type' of ServerResponseThread (SRT) different actions will be taken
 * when the server does not respond within the set time frame.
 *
 * @author Chrisb
 */

public abstract class ServerResponseThread extends Thread {
    protected abstract void onTimeout();
    public abstract void run();

    public void setOutgoingPacket(DatagramPacket packet) { outgoingPacket = packet; }
    public DatagramPacket getOutgoingPacket() { return outgoingPacket; }

    public void start() { running = this; super.start(); }
    public void stopThread() { running = null; }

    protected volatile Thread running;
    protected DatagramPacket outgoingPacket;
    protected DatagramPacket incomingPacket;

    protected byte[] incoming;
    protected byte[] outgoing;
    protected DatagramSocket socket;
    protected InetAddress address;

    protected static final int PORT = 2222;
    protected static final int GAME_PORT = 2024;
}